//
//  TopMenuViewController.m
//  SKStock
//
//  Created by thPark on 11. 1. 3..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "TopMenuViewController.h"

#import "SettingViewController.h"

@implementation TopMenuViewController

@synthesize _delegate;

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	_btnBack.hidden = YES;
	_btnModify.hidden = YES;
	_btnErase.hidden = YES;
    _btnSetting.hidden = YES;
    _btnCancel.hidden = YES;
	
	if(_viewIdx == CHERRY_MENU_CARDDETAIL){
		_labTitle.text = @"카드 상세 정보";
	}else if(_viewIdx == CHERRY_MENU_SETTING){
		_labTitle.text = @"설정";
	}    
    
	if(_leftBtnType == TOP_LEFT_BACK){
		_btnBack.hidden = NO;
	}
	
	if(_rightBtnType == TOP_RIGHT_MODIFY){
		_btnModify.hidden = NO;
	}else if(_rightBtnType == TOP_RIGHT_ERASE){
		_btnErase.hidden = NO;
	}else if(_rightBtnType == TOP_RIGHT_SETTING){
        _btnSetting.hidden = NO;
    }else if(_rightBtnType == TOP_RIGHT_CANCEL){
        _btnCancel.hidden = NO;
    }
}

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc {
//	LOG_DEALLOC(@"======== Start");
	G__SAFE_FREE(_labTitle);
    G__SAFE_FREE(_btnBack);
    G__SAFE_FREE(_btnModify);
    G__SAFE_FREE(_btnErase);
	G__SAFE_FREE(_btnSetting);
    
	_delegate = nil;
    [super dealloc];
//	LOG_DEALLOC(@"======== End");
}

#pragma -

- (void)setVController:(UIViewController *)vc{
    _VC = vc;
}

- (void) initWithMenuType:(int)type{
	_viewIdx = type;
}

- (void)initTopMenuBtnType:(int)left right:(int)right{
	_leftBtnType = left;
	_rightBtnType = right;
}

- (void)chgTopMenuBtnType:(int)left right:(int)right{

	_btnBack.hidden = YES;
	_btnModify.hidden = YES;
	_btnErase.hidden = YES;
    _btnSetting.hidden = YES;
    _btnCancel.hidden = YES;
	
	_leftBtnType = left;
	_rightBtnType = right;
	
    if(_leftBtnType == TOP_LEFT_BACK){
		_btnBack.hidden = NO;
	}
	
	if(_rightBtnType == TOP_RIGHT_MODIFY){
		_btnModify.hidden = NO;
	}else if(_rightBtnType == TOP_RIGHT_ERASE){
		_btnErase.hidden = NO;
	}else if(_rightBtnType == TOP_RIGHT_SETTING){
        _btnSetting.hidden = NO;
    }else if(_rightBtnType == TOP_RIGHT_CANCEL){
        _btnCancel.hidden = NO;
    }
}

- (void)changeTitleText:(NSString*)name{
	_labTitle.text = name;
}

#pragma - IBAction

- (IBAction) goBack{
	if ([_delegate respondsToSelector:@selector(topMenuVCClickLeft)]){
		[_delegate topMenuVCClickLeft];
	}else{
//		[[SKStockMainViewController getInstance] popView:YES];
        [[_VC navigationController] popViewControllerAnimated:YES];
	}
}

- (IBAction) goErase{
	if ([_delegate respondsToSelector:@selector(topMenuVCClickRight)]){
		[_delegate topMenuVCClickRight];
	}else{
//		[[SKStockMainViewController getInstance] popView:YES];
	}
}

- (IBAction) goModify{
	if ([_delegate respondsToSelector:@selector(topMenuVCClickRight)]){
		[_delegate topMenuVCClickRight];
	}else{
        
	}
}

- (IBAction) goSetting{
    if ([_delegate respondsToSelector:@selector(topMenuVCClickRight)]){
		[_delegate topMenuVCClickRight];
	}else{
        SettingViewController *settingVC = [[SettingViewController alloc] initWithNibName:@"SettingViewController" bundle:nil];
        [[_VC navigationController] pushViewController:settingVC animated:YES];
        [settingVC release];
	}
}

- (IBAction) goCancel{
    if ([_delegate respondsToSelector:@selector(topMenuVCClickRight)]){
		[_delegate topMenuVCClickRight];
	}else{

	}
}

//- (NSString*)getTitle{
//	return _labTitle.text;
//}

@end
